<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE Unsafe #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE NoImplicitPrelude #-}</span><span>
</span><span id="line-3"></span><span>
</span><span id="line-4"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-5"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-6"></span><span class="hs-comment">-- Module      :  System.IO.Unsafe</span><span>
</span><span id="line-7"></span><span class="hs-comment">-- Copyright   :  (c) The University of Glasgow 2001</span><span>
</span><span id="line-8"></span><span class="hs-comment">-- License     :  BSD-style (see the file libraries/base/LICENSE)</span><span>
</span><span id="line-9"></span><span class="hs-comment">-- </span><span>
</span><span id="line-10"></span><span class="hs-comment">-- Maintainer  :  libraries@haskell.org</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- Stability   :  provisional</span><span>
</span><span id="line-12"></span><span class="hs-comment">-- Portability :  portable</span><span>
</span><span id="line-13"></span><span class="hs-comment">--</span><span>
</span><span id="line-14"></span><span class="hs-comment">-- \&quot;Unsafe\&quot; IO operations.</span><span>
</span><span id="line-15"></span><span class="hs-comment">--</span><span>
</span><span id="line-16"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-17"></span><span>
</span><span id="line-18"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">System.IO.Unsafe</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-19"></span><span>   </span><span class="annot"><span class="hs-comment">-- * Unsafe 'System.IO.IO' operations</span></span><span>
</span><span id="line-20"></span><span>   </span><span class="annot"><a href="GHC.IO.Unsafe.html#unsafePerformIO"><span class="hs-identifier">unsafePerformIO</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-21"></span><span>   </span><span class="annot"><a href="GHC.IO.Unsafe.html#unsafeDupablePerformIO"><span class="hs-identifier">unsafeDupablePerformIO</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-22"></span><span>   </span><span class="annot"><a href="GHC.IO.Unsafe.html#unsafeInterleaveIO"><span class="hs-identifier">unsafeInterleaveIO</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-23"></span><span>   </span><span class="annot"><a href="System.IO.Unsafe.html#unsafeFixIO"><span class="hs-identifier">unsafeFixIO</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-24"></span><span>  </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-25"></span><span>
</span><span id="line-26"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Base.html"><span class="hs-identifier">GHC.Base</span></a></span><span>
</span><span id="line-27"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.html"><span class="hs-identifier">GHC.IO</span></a></span><span>
</span><span id="line-28"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IORef.html"><span class="hs-identifier">GHC.IORef</span></a></span><span>
</span><span id="line-29"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Exception.html"><span class="hs-identifier">GHC.Exception</span></a></span><span>
</span><span id="line-30"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Control.Exception.html"><span class="hs-identifier">Control.Exception</span></a></span><span>
</span><span id="line-31"></span><span>
</span><span id="line-32"></span><span class="hs-comment">-- | A slightly faster version of `System.IO.fixIO` that may not be</span><span>
</span><span id="line-33"></span><span class="hs-comment">-- safe to use with multiple threads.  The unsafety arises when used</span><span>
</span><span id="line-34"></span><span class="hs-comment">-- like this:</span><span>
</span><span id="line-35"></span><span class="hs-comment">--</span><span>
</span><span id="line-36"></span><span class="hs-comment">-- &gt;  unsafeFixIO $ \r -&gt; do</span><span>
</span><span id="line-37"></span><span class="hs-comment">-- &gt;     forkIO (print r)</span><span>
</span><span id="line-38"></span><span class="hs-comment">-- &gt;     return (...)</span><span>
</span><span id="line-39"></span><span class="hs-comment">--</span><span>
</span><span id="line-40"></span><span class="hs-comment">-- In this case, the child thread will receive a @NonTermination@</span><span>
</span><span id="line-41"></span><span class="hs-comment">-- exception instead of waiting for the value of @r@ to be computed.</span><span>
</span><span id="line-42"></span><span class="hs-comment">--</span><span>
</span><span id="line-43"></span><span class="hs-comment">-- @since 4.5.0.0</span><span>
</span><span id="line-44"></span><span id="local-6989586621679531004"><span class="annot"><a href="System.IO.Unsafe.html#unsafeFixIO"><span class="hs-identifier hs-type">unsafeFixIO</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679531004"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531004"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531004"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-45"></span><span id="unsafeFixIO"><span class="annot"><span class="annottext">unsafeFixIO :: forall a. (a -&gt; IO a) -&gt; IO a
</span><a href="System.IO.Unsafe.html#unsafeFixIO"><span class="hs-identifier hs-var hs-var">unsafeFixIO</span></a></span></span><span> </span><span id="local-6989586621679530978"><span class="annot"><span class="annottext">a -&gt; IO a
</span><a href="#local-6989586621679530978"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-46"></span><span>  </span><span id="local-6989586621679530977"><span class="annot"><span class="annottext">IORef a
</span><a href="#local-6989586621679530977"><span class="hs-identifier hs-var">ref</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">a -&gt; IO (IORef a)
forall a. a -&gt; IO (IORef a)
</span><a href="GHC.IORef.html#newIORef"><span class="hs-identifier hs-var">newIORef</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">NonTermination -&gt; a
forall a e. Exception e =&gt; e -&gt; a
</span><a href="GHC.Exception.html#throw"><span class="hs-identifier hs-var">throw</span></a></span><span> </span><span class="annot"><span class="annottext">NonTermination
</span><a href="Control.Exception.Base.html#NonTermination"><span class="hs-identifier hs-var">NonTermination</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-47"></span><span>  </span><span id="local-6989586621679530973"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679530973"><span class="hs-identifier hs-var">ans</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO a -&gt; IO a
forall a. IO a -&gt; IO a
</span><a href="GHC.IO.Unsafe.html#unsafeDupableInterleaveIO"><span class="hs-identifier hs-var">unsafeDupableInterleaveIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IORef a -&gt; IO a
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef a
</span><a href="#local-6989586621679530977"><span class="hs-identifier hs-var">ref</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-48"></span><span>  </span><span id="local-6989586621679530970"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679530970"><span class="hs-identifier hs-var">result</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">a -&gt; IO a
</span><a href="#local-6989586621679530978"><span class="hs-identifier hs-var">k</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679530973"><span class="hs-identifier hs-var">ans</span></a></span><span>
</span><span id="line-49"></span><span>  </span><span class="annot"><span class="annottext">IORef a -&gt; a -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef a
</span><a href="#local-6989586621679530977"><span class="hs-identifier hs-var">ref</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679530970"><span class="hs-identifier hs-var">result</span></a></span><span>
</span><span id="line-50"></span><span>  </span><span class="annot"><span class="annottext">a -&gt; IO a
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679530970"><span class="hs-identifier hs-var">result</span></a></span><span>
</span><span id="line-51"></span></pre></body></html>